/** note 转 csv */
export const convertToCSVFormat = (notes: Note[]) => {
  let csvContent = "id,title,body,updated\n"; // CSV 格式的标题行
  for (let i = 0; i < notes.length; i++) {
    const { id, title, body, updated } = notes[i];
    const csvLine = `${id},${title},${body},${updated}`;
    csvContent += csvLine + "\n";
  }
  return csvContent;
};

/** csv 转 note */
export const parseCSVFileContent = (fileContent: string) => {
  if (!fileContent) return;
  const lines = fileContent.split("\n").filter((item) => item);
  const notes = [];
  for (let i = 1; i < lines.length; i++) {
    const [id, title, body, updated] = lines[i].split(",");
    notes.push({ id, title, body, updated });
  }
  return notes;
};
